<template>
    <div class="app-container">
      <el-form :model="form" label-width="120px" :rules="rules" ref="form" status-icon>
        <el-form-item label="项目名称" prop="projectName" required>
          <!-- <span style="color: red">*</span> -->
          <el-input v-model="form.projectName" placeholder="请输入项目名称"></el-input>
        </el-form-item>
        
        <el-form-item label="评估方法" prop="evaluationMethod" required>
          <!-- <span style="color: red">*</span> -->
          <el-select v-model="form.evaluationMethod" placeholder="请选择评估方法">
            <el-option label="方法一" value="method1"></el-option>
            <el-option label="方法二" value="method2"></el-option>
            <!-- 可以添加更多选项 -->
          </el-select>
        </el-form-item>
        
        <el-form-item label="计算模型" prop="calculationModel" required>
          <!-- <span style="color: red">*</span> -->
          <el-select v-model="form.calculationModel" placeholder="请选择计算模型">
            <el-option label="模型一" value="model1"></el-option>
            <el-option label="模型二" value="model2"></el-option>
            <!-- 可以添加更多选项 -->
          </el-select>
        </el-form-item>
        
        <el-form-item label="上传文件" prop="fileList" required>
          <!-- <span style="color: red">*</span> -->
          <el-upload
            action="#"
            :before-upload="beforeUpload"
            :on-change="handleFileChange"
            :file-list="fileList"
            accept=".doc,.docx"
            :limit="1"
          >
            <el-button type="primary">点击上传</el-button>
          </el-upload>
          <div v-if="fileList.length === 0" style="color: black">请上传word格式文件</div>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" @click="submitForm">确定</el-button>
        </el-form-item>
      </el-form>
    </div>
  </template>
  
  <script>
  export default {
    name: 'UserManage',
    data() {
      return {
        form: {
          projectName: '',
          evaluationMethod: '',
          calculationModel: '',
        },
        fileList: [],
        rules: {
          projectName: [
            { required: true, message: '请输入项目名称', trigger: 'blur' }
          ],
          evaluationMethod: [
            { required: true, message: '请选择评估方法', trigger: 'change' }
          ],
          calculationModel: [
            { required: true, message: '请选择计算模型', trigger: 'change' }
          ],
          fileList: [
            { validator: this.validateFile, trigger: 'change' }
          ]
        }
      }
    },
    methods: {
      beforeUpload(file) {
        const isWord = file.type === 'application/msword' || file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
        if (!isWord) {
          this.$message.error('上传文件只能是 Word 格式!');
        }
        return isWord;
      },
      handleFileChange(file, fileList) {
        this.fileList = fileList;
      },
      validateFile(rule, value, callback) {
        if (this.fileList.length === 0) {
          callback(new Error('您尚未上传文件'));
        } else {
          callback();
        }
      },
      submitForm() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.$message.success('表单提交成功，进入下一个界面');
            // 示例：导航到下一个页面
            // this.$router.push('/next-page');
          } else {
            this.$message.error('请完整填写所有信息');
            return false;
          }
        });
      }
    }
  }
  </script>
  
  <style scoped>
  .app-container {
    padding: 20px;
  }
  </style>
  